// 导入axios实例
import httpRequest from '../request/index';
// sha256加密
import sha256 from 'crypto-js/sha256';


// 添加动漫链接
export function addAnimationLink(alink) {
    alink['time'] = Math.round(new Date().getTime() / 1000);
    let params = `${alink.name}${alink.url}XpFaEDYkQH`;
    alink['sign'] = sha256(params).toString().substring(0, 15);
    return httpRequest({
        baseURL: '/admin',
        url: `/alink/add`,
        method: 'post',
        data: alink,
        headers: { Authorization: `Bearer ${window.sessionStorage.getItem('token')}` }
    });
}


// 删除动漫链接
export function deleteAnimationLink(id) {
    let sign = sha256(id + 'XpFaEDYkQH').toString().substring(0, 15);
    return httpRequest({
        baseURL: '/admin',
        url: `/alink/${id}?time=${Math.round(new Date().getTime() / 1000)}&sign=${sign}`,
        method: 'delete',
        headers: { Authorization: `Bearer ${window.sessionStorage.getItem('token')}` }
    });
}


// 编辑动漫链接
export function editAnimationLink(id, alink) {
    alink['time'] = Math.round(new Date().getTime() / 1000);
    let params = `${alink.name}${alink.url}XpFaEDYkQH`;
    alink['sign'] = sha256(params).toString().substring(0, 15);
    return httpRequest({
        baseURL: '/admin',
        url: `/alink/${id}`,
        method: 'put',
        data: alink,
        headers: { Authorization: `Bearer ${window.sessionStorage.getItem('token')}` }
    });
}
